from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
from langchain_core.tools import tool

from common.ali_qwen import get_model

# 初始化语言模型
model = get_model()

# 定义一个简单的工具来获取天气信息
@tool
def get_weather(city: str):
    """Use this tool to get the weather information for a city."""
    if city.lower() in ["上海", "北京"]:
        return f"{city}天气很好"
    elif city.lower() in ["广州", "深圳"]:
        return f"{city}天气糟糕"
    else:
        return "请查看中国天气网"

tools = [get_weather]
chinese_prompt = "请用英文回复所有问题"
# 创建 ReAct 智能体
graph = create_react_agent(model, tools=tools,prompt=chinese_prompt)

# 调用智能体
inputs = {"messages": [("user", "北京的天气如何？简要回答，不需要额外信息,得到的消息翻译成英文")]}
response = graph.invoke(inputs)
print(response['messages'][-1].content)